//
//  DKAuthFaceLoadView.m
//  DanKU
//
//  Created by 蓝鳍互娱 on 2023/12/5.
//

#import "DKAuthFaceLoadView.h"
//#import "NVActivityIndicatorView-Swift.h"
@interface DKAuthFaceLoadView()
@property (nonatomic, copy)void(^SureAuthFaceLoadAlertBlock)(void);

//@property (nonatomic,strong) NVActivityIndicatorView *dk_LoadView;
@end
@implementation DKAuthFaceLoadView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.clearColor;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    UIView *dk_AuthFaceLoadBgView = [[UIView alloc] init];
    dk_AuthFaceLoadBgView.backgroundColor = DK_HexA(@"#333333",0.89);
    dk_AuthFaceLoadBgView.layer.cornerRadius = DK_IsWidthScale(10);
    [self addSubview:dk_AuthFaceLoadBgView];
    [dk_AuthFaceLoadBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self);
        make.width.equalTo(@(DK_IsWidthScale(224)));
        make.height.equalTo(@(DK_IsWidthScale(110)));
    }];
    UIImageView* dk_AuthFaceLoadView = [[UIImageView alloc] init];
    dk_AuthFaceLoadView.userInteractionEnabled = YES;
    dk_AuthFaceLoadView.image = DK_GetImage(@"dk_AuthLoad");
    [dk_AuthFaceLoadBgView addSubview:dk_AuthFaceLoadView];
    [dk_AuthFaceLoadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(@(DK_IsWidthScale(20)));
        make.width.equalTo(@(DK_IsWidthScale(44)));
        make.height.equalTo(@(DK_IsWidthScale(44)));
    }];
    [self rotation:dk_AuthFaceLoadView];
//    self.dk_LoadView = [NVActivityIndicatorView ];
//    self.dk_LoadView.color = DK_Hex(@"#FC9300");
//    [dk_AuthFaceLoadBgView addSubview:self.dk_LoadView];
//    [self.dk_LoadView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self);
//        make.top.equalTo(@(DK_IsWidthScale(20)));
//        make.width.equalTo(@(DK_IsWidthScale(44)));
//        make.height.equalTo(@(DK_IsWidthScale(44)));
//    }];
    UILabel *dk_AuthLoadAlertLab = [[UILabel alloc] init];
    dk_AuthLoadAlertLab.textColor = DK_Hex(@"#FFFFFF");
    dk_AuthLoadAlertLab.font = DK_FONT_Regular(14);
    dk_AuthLoadAlertLab.text = @"Loading, wait";
    dk_AuthLoadAlertLab.textAlignment = NSTextAlignmentCenter;
    [dk_AuthFaceLoadBgView addSubview:dk_AuthLoadAlertLab];
    [dk_AuthLoadAlertLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@(-DK_IsWidthScale(17)));
        make.height.equalTo(@(DK_IsWidthScale(20)));
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
    }];
}
- (void)rotation:(UIImageView *)dk_AuthFaceLoadView{
    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 1;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = MAXFLOAT;
    rotationAnimation.removedOnCompletion = NO;
    [dk_AuthFaceLoadView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
+ (DKAuthFaceLoadView *)dk_ShowAuthFaceLoadAlertView:(void(^)(void))complete{
    DKAuthFaceLoadView * dk_AuthFaceLoadView = [[DKAuthFaceLoadView alloc] init];
    zhPopupController * sureAuthStartCtrl = [[zhPopupController alloc] initWithView:dk_AuthFaceLoadView size:CGSizeMake(DK_SCREEN_W, DK_SCREEN_H)];
    dk_AuthFaceLoadView.SureAuthFaceLoadAlertBlock = complete;
    sureAuthStartCtrl.maskType = zhPopupMaskTypeClear;
    sureAuthStartCtrl.presentationStyle = zhPopupSlideStyleTransform;
    sureAuthStartCtrl.layoutType = zhPopupLayoutTypeCenter;
    sureAuthStartCtrl.presentationTransformScale = 0.56;
    sureAuthStartCtrl.dismissonTransformScale = 0.56;
    sureAuthStartCtrl.dismissOnMaskTouched = NO;
    dk_AuthFaceLoadView.dk_AuthFaceLoadViewPop = sureAuthStartCtrl;
    [sureAuthStartCtrl showInView:((AppDelegate*)([UIApplication sharedApplication].delegate)).window completion:^{
        complete();
    }];
    return dk_AuthFaceLoadView;
}
@end
